//==============================================================================
// CellML file:   C:\Program Files\COR\Models\luo_rudy_I_model_1991.cellml
// CellML model:  luo_rudy_I_model_1991
// Date and time: 2007-11-13 at 18:48:22
//------------------------------------------------------------------------------
// Conversion from CellML 1.0 to Java was done using COR (0.9.31.813)
//    Copyright 2002-2007 Dr Alan Garny
//    http://COR.physiol.ox.ac.uk/ - COR@physiol.ox.ac.uk
//------------------------------------------------------------------------------
// http://www.CellML.org/
//==============================================================================

public class luo_rudy_I_model_1991
{
   public int _NB_OF_STATE_VARIABLES_ = 8;

   //---------------------------------------------------------------------------
   // State variables
   //---------------------------------------------------------------------------

   public double[] Y = new double[_NB_OF_STATE_VARIABLES_];
   public double[] dY = new double[_NB_OF_STATE_VARIABLES_];
   // 0: fast_sodium_current_h_gate___h (dimensionless)
   // 1: fast_sodium_current_j_gate___j (dimensionless)
   // 2: fast_sodium_current_m_gate___m (dimensionless)
   // 3: intracellular_calcium_concentration___Cai (concentration_units)
   // 4: membrane___V (millivolt)
   // 5: slow_inward_current_d_gate___d (dimensionless)
   // 6: slow_inward_current_f_gate___f (dimensionless)
   // 7: time_dependent_potassium_current_X_gate___X (dimensionless)

   //---------------------------------------------------------------------------
   // Constants
   //---------------------------------------------------------------------------

   public double background_current___E_b;   // millivolt
   public double background_current___g_b;   // milliS_per_cm2
   public double fast_sodium_current___g_Na;   // milliS_per_cm2
   public double ionic_concentrations___Ki;   // concentration_units
   public double ionic_concentrations___Ko;   // concentration_units
   public double ionic_concentrations___Nai;   // concentration_units
   public double ionic_concentrations___Nao;   // concentration_units
   public double membrane___C;   // microF_per_cm2
   public double membrane___F;   // coulomb_per_mole
   public double membrane___R;   // joule_per_kilomole_kelvin
   public double membrane___T;   // kelvin
   public double membrane___stim_amplitude;   // microA_per_cm2
   public double membrane___stim_duration;   // millisecond
   public double membrane___stim_end;   // millisecond
   public double membrane___stim_period;   // millisecond
   public double membrane___stim_start;   // millisecond
   public double plateau_potassium_current___g_Kp;   // milliS_per_cm2
   public double time_dependent_potassium_current___PR_NaK;   // dimensionless

   //---------------------------------------------------------------------------
   // Computed variables
   //---------------------------------------------------------------------------

   public double background_current___i_b;   // microA_per_cm2
   public double fast_sodium_current___E_Na;   // millivolt
   public double fast_sodium_current___i_Na;   // microA_per_cm2
   public double fast_sodium_current_h_gate___alpha_h;   // per_millisecond
   public double fast_sodium_current_h_gate___beta_h;   // per_millisecond
   public double fast_sodium_current_j_gate___alpha_j;   // per_millisecond
   public double fast_sodium_current_j_gate___beta_j;   // per_millisecond
   public double fast_sodium_current_m_gate___alpha_m;   // per_millisecond
   public double fast_sodium_current_m_gate___beta_m;   // per_millisecond
   public double membrane___I_stim;   // microA_per_cm2
   public double plateau_potassium_current___E_Kp;   // millivolt
   public double plateau_potassium_current___Kp;   // dimensionless
   public double plateau_potassium_current___i_Kp;   // microA_per_cm2
   public double slow_inward_current___E_si;   // millivolt
   public double slow_inward_current___i_si;   // microA_per_cm2
   public double slow_inward_current_d_gate___alpha_d;   // per_millisecond
   public double slow_inward_current_d_gate___beta_d;   // per_millisecond
   public double slow_inward_current_f_gate___alpha_f;   // per_millisecond
   public double slow_inward_current_f_gate___beta_f;   // per_millisecond
   public double time_dependent_potassium_current_X_gate___alpha_X;   // per_millisecond
   public double time_dependent_potassium_current_X_gate___beta_X;   // per_millisecond
   public double time_dependent_potassium_current_Xi_gate___Xi;   // dimensionless
   public double time_dependent_potassium_current___E_K;   // volt
   public double time_dependent_potassium_current___g_K;   // milliS_per_cm2
   public double time_dependent_potassium_current___i_K;   // microA_per_cm2
   public double time_independent_potassium_current_K1_gate___K1_infinity;   // dimensionless
   public double time_independent_potassium_current_K1_gate___alpha_K1;   // per_millisecond
   public double time_independent_potassium_current_K1_gate___beta_K1;   // per_millisecond
   public double time_independent_potassium_current___E_K1;   // millivolt
   public double time_independent_potassium_current___g_K1;   // milliS_per_cm2
   public double time_independent_potassium_current___i_K1;   // microA_per_cm2

   //---------------------------------------------------------------------------
   // Initialisation
   //---------------------------------------------------------------------------

   public void init()
   {
      //------------------------------------------------------------------------
      // State variables
      //------------------------------------------------------------------------

      Y[0] = 0.9804713;   // fast_sodium_current_h_gate___h (dimensionless)
      Y[1] = 0.98767124;   // fast_sodium_current_j_gate___j (dimensionless)
      Y[2] = 0.00187018;   // fast_sodium_current_m_gate___m (dimensionless)
      Y[3] = 0.0002;   // intracellular_calcium_concentration___Cai(concentration_units)
      Y[4] = -83.853;   // membrane___V (millivolt)
      Y[5] = 0.00316354;   // slow_inward_current_d_gate___d (dimensionless)
      Y[6] = 0.99427859;   // slow_inward_current_f_gate___f (dimensionless)
      Y[7] = 0.16647703;   // time_dependent_potassium_current_X_gate___X (dimensionless)

      //------------------------------------------------------------------------
      // Constants
      //------------------------------------------------------------------------

      background_current___E_b = -59.87;   // millivolt
      background_current___g_b = 0.03921;   // milliS_per_cm2
      fast_sodium_current___g_Na = 23.0;   // milliS_per_cm2
      ionic_concentrations___Ki = 145.0;   // concentration_units
      ionic_concentrations___Ko = 5.4;   // concentration_units
      ionic_concentrations___Nai = 18.0;   // concentration_units
      ionic_concentrations___Nao = 140.0;   // concentration_units
      membrane___C = 1.0;   // microF_per_cm2
      membrane___F = 96484.6;   // coulomb_per_mole
      membrane___R = 8314.0;   // joule_per_kilomole_kelvin
      membrane___T = 310.0;   // kelvin
      membrane___stim_amplitude = -25.5;   // microA_per_cm2
      membrane___stim_duration = 2.0;   // millisecond
      membrane___stim_end = 20000.0;   // millisecond
      membrane___stim_period = 1000.0;   // millisecond
      membrane___stim_start = 100.0;   // millisecond
      plateau_potassium_current___g_Kp = 0.0183;   // milliS_per_cm2
      time_dependent_potassium_current___PR_NaK = 0.01833;   // dimensionless
   }

   //---------------------------------------------------------------------------
   // Computation
   //---------------------------------------------------------------------------

   public void compute(double t)
   {
      // t: time (millisecond)

      background_current___i_b = background_current___g_b*(Y[4]-background_current___E_b);
      fast_sodium_current___E_Na = membrane___R*membrane___T/membrane___F*Math.log(ionic_concentrations___Nao/ionic_concentrations___Nai);
      fast_sodium_current___i_Na = fast_sodium_current___g_Na*Math.pow(Y[2], 3.0)*Y[0]*Y[1]*(Y[4]-fast_sodium_current___E_Na);

      if (Y[4] < -40.0)
         fast_sodium_current_h_gate___alpha_h = 0.135*Math.exp((80.0+Y[4])/-6.8);
      else
         fast_sodium_current_h_gate___alpha_h = 0.0;

      if (Y[4] < -40.0)
         fast_sodium_current_h_gate___beta_h = 3.56*Math.exp(0.079*Y[4])+310000.0*Math.exp(0.35*Y[4]);
      else
         fast_sodium_current_h_gate___beta_h = 1.0/(0.13*(1.0+Math.exp((Y[4]+10.66)/-11.1)));

      dY[0] = fast_sodium_current_h_gate___alpha_h*(1.0-Y[0])-fast_sodium_current_h_gate___beta_h*Y[0];

      if (Y[4] < -40.0)
         fast_sodium_current_j_gate___alpha_j = (-127140.0*Math.exp(0.2444*Y[4])-0.00003474*Math.exp(-0.04391*Y[4]))*(Y[4]+37.78)/(1.0+Math.exp(0.311*(Y[4]+79.23)));
      else
         fast_sodium_current_j_gate___alpha_j = 0.0;

      if (Y[4] < -40.0)
         fast_sodium_current_j_gate___beta_j = 0.1212*Math.exp(-0.01052*Y[4])/(1.0+Math.exp(-0.1378*(Y[4]+40.14)));
      else
         fast_sodium_current_j_gate___beta_j = 0.3*Math.exp(-0.0000002535*Y[4])/(1.0+Math.exp(-0.1*(Y[4]+32.0)));

      dY[1] = fast_sodium_current_j_gate___alpha_j*(1.0-Y[1])-fast_sodium_current_j_gate___beta_j*Y[1];
      fast_sodium_current_m_gate___alpha_m = 0.32*(Y[4]+47.13)/(1.0-Math.exp(-0.1*(Y[4]+47.13)));
      fast_sodium_current_m_gate___beta_m = 0.08*Math.exp(-Y[4]/11.0);
      dY[2] = fast_sodium_current_m_gate___alpha_m*(1.0-Y[2])-fast_sodium_current_m_gate___beta_m*Y[2];
      slow_inward_current___E_si = 7.7-13.0287*Math.log(Y[3]);
      slow_inward_current___i_si = 0.09*Y[5]*Y[6]*(Y[4]-slow_inward_current___E_si);
      dY[3] = -0.0001*slow_inward_current___i_si+0.07*(0.0001-Y[3]);

      if ((t >= membrane___stim_start) && (t <= membrane___stim_end) && (t-membrane___stim_start-Math.floor((t-membrane___stim_start)/membrane___stim_period)*membrane___stim_period <= membrane___stim_duration))
         membrane___I_stim = membrane___stim_amplitude;
      else
         membrane___I_stim = 0.0;

      time_dependent_potassium_current___g_K = 0.282*Math.sqrt(ionic_concentrations___Ko/5.4);

      if (Y[4] > -100.0)
         time_dependent_potassium_current_Xi_gate___Xi = 2.837*(Math.exp(0.04*(Y[4]+77.0))-1.0)/((Y[4]+77.0)*Math.exp(0.04*(Y[4]+35.0)));
      else
         time_dependent_potassium_current_Xi_gate___Xi = 1.0;

      time_dependent_potassium_current___E_K = membrane___R*membrane___T/membrane___F*Math.log((ionic_concentrations___Ko+time_dependent_potassium_current___PR_NaK*ionic_concentrations___Nao)/(ionic_concentrations___Ki+time_dependent_potassium_current___PR_NaK*ionic_concentrations___Nai));
      time_dependent_potassium_current___i_K = time_dependent_potassium_current___g_K*Y[7]*time_dependent_potassium_current_Xi_gate___Xi*(Y[4]-time_dependent_potassium_current___E_K);
      time_independent_potassium_current___g_K1 = 0.6047*Math.sqrt(ionic_concentrations___Ko/5.4);
      time_independent_potassium_current___E_K1 = membrane___R*membrane___T/membrane___F*Math.log(ionic_concentrations___Ko/ionic_concentrations___Ki);
      time_independent_potassium_current_K1_gate___alpha_K1 = 1.02/(1.0+Math.exp(0.2385*(Y[4]-time_independent_potassium_current___E_K1-59.215)));
      time_independent_potassium_current_K1_gate___beta_K1 = (0.49124*Math.exp(0.08032*(Y[4]+5.476-time_independent_potassium_current___E_K1))+Math.exp(0.06175*(Y[4]-(time_independent_potassium_current___E_K1+594.31))))/(1.0+Math.exp(-0.5143*(Y[4]-time_independent_potassium_current___E_K1+4.753)));
      time_independent_potassium_current_K1_gate___K1_infinity = time_independent_potassium_current_K1_gate___alpha_K1/(time_independent_potassium_current_K1_gate___alpha_K1+time_independent_potassium_current_K1_gate___beta_K1);
      time_independent_potassium_current___i_K1 = time_independent_potassium_current___g_K1*time_independent_potassium_current_K1_gate___K1_infinity*(Y[4]-time_independent_potassium_current___E_K1);
      plateau_potassium_current___Kp = 1.0/(1.0+Math.exp((7.488-Y[4])/5.98));
      plateau_potassium_current___E_Kp = time_independent_potassium_current___E_K1;
      plateau_potassium_current___i_Kp = plateau_potassium_current___g_Kp*plateau_potassium_current___Kp*(Y[4]-plateau_potassium_current___E_Kp);
      dY[4] = -1.0/membrane___C*(membrane___I_stim+fast_sodium_current___i_Na+slow_inward_current___i_si+time_dependent_potassium_current___i_K+time_independent_potassium_current___i_K1+plateau_potassium_current___i_Kp+background_current___i_b);
      slow_inward_current_d_gate___alpha_d = 0.095*Math.exp(-0.01*(Y[4]-5.0))/(1.0+Math.exp(-0.072*(Y[4]-5.0)));
      slow_inward_current_d_gate___beta_d = 0.07*Math.exp(-0.017*(Y[4]+44.0))/(1.0+Math.exp(0.05*(Y[4]+44.0)));
      dY[5] = slow_inward_current_d_gate___alpha_d*(1.0-Y[5])-slow_inward_current_d_gate___beta_d*Y[5];
      slow_inward_current_f_gate___alpha_f = 0.012*Math.exp(-0.008*(Y[4]+28.0))/(1.0+Math.exp(0.15*(Y[4]+28.0)));
      slow_inward_current_f_gate___beta_f = 0.0065*Math.exp(-0.02*(Y[4]+30.0))/(1.0+Math.exp(-0.2*(Y[4]+30.0)));
      dY[6] = slow_inward_current_f_gate___alpha_f*(1.0-Y[6])-slow_inward_current_f_gate___beta_f*Y[6];
      time_dependent_potassium_current_X_gate___alpha_X = 0.0005*Math.exp(0.083*(Y[4]+50.0))/(1.0+Math.exp(0.057*(Y[4]+50.0)));
      time_dependent_potassium_current_X_gate___beta_X = 0.0013*Math.exp(-0.06*(Y[4]+20.0))/(1.0+Math.exp(-0.04*(Y[4]+20.0)));
      dY[7] = time_dependent_potassium_current_X_gate___alpha_X*(1.0-Y[7])-time_dependent_potassium_current_X_gate___beta_X*Y[7];
   }
}

//==============================================================================
// End of file
//==============================================================================
